<?php
    include_once ('inc/class/User.class.php');
    include_once ('inc/global/global.inc.php');
    include_once ('inc/code/headIndex.php');
    include_once ('inc/class/Form.class.php');
    include_once ('inc/class/Util.class.php');


    if(!isset($utente))
        $utente = new User();

    if(($_GET["id"]) == 1){
        
       User::registra_utente($_POST['name'],$_POST['cognome'],$_POST['email'],$_POST['username'],$_POST['password'],$_POST['number'],$_POST['cap'],$_POST['citta'],$_POST['date'],$_POST['indirizzo']);
        

       Util::logoutRedirect();
    }


?>
<div id="Content">

 <div id="One">


          <H2>&raquo; Registrati</H2>

            </blockquote>
                    <fieldset>
                    <legend>Registrazione</legend>

		<section class='form'>
                    <form action="?id=1" method="post" name="registrazione">

					<div class="item">
						<label>
							<span>Nome</span>
							<input  name="name" placeholder="ex. John" required="required" type="text" />
						</label>
                                            </div>
                                    <div class="item">
                                                <label>
							<span>Cognome</span>
							<input   name="cognome" placeholder="ex. Smith" required="required" type="text" />
						</label>

					</div>

					<div class="item">
						<label>
							<span>Email</span>
							<input name="email" class='email' required="required" type="email" />
						</label>
                                                <div class='tooltip help'>
							<span>?</span>
							<div class='content'>
								<b></b>
								<p>Inserire un email valida: esempio@esempio.esempio</p>
							</div>
						</div>
					</div>
					<div class="item">
						<label>
							<span>Confemra email</span>
							<input type="email" class='email' name="confirm_email" data-validate-linked='email' required='required'>
						</label>
					</div>
					<div class="item">
						<label>
							<span>Numero di telefono</span>
							<input type="number" class='number' name="number" data-validate-length="10,100" data-validate-pattern="numeric" required='required'>
						</label>
						<div class='tooltip help'>
							<span>?</span>
							<div class='content'>
								<b></b>
								<p>Numero deve essere tra 10 e 100</p>
							</div>
						</div>
					</div>
					<div class="item">
						<label>
							<span>Data di nascita</span>
							<input class='date' type="date" name="date" required='required'>
						</label>
					</div>
                                    <div class="item">
						<label>
							<span>CAP</span>
							<input type="number" class='number' name="cap" data-validate-minmax="1000,9999" data-validate-pattern="numeric" required='required'>
						</label>
						<div class='tooltip help'>
							<span>?</span>
							<div class='content'>
								<b></b>
								<p>Numero deve essere tra 1000 e 9999</p>
							</div>
						</div>
					</div>
                                    <div class="item">
                                                <label>
							<span>Citta</span>
							<input   name="citta" placeholder="Lugano Capitale" required="required" type="text" />
						</label>

					</div>
                                    <div class="item">
                                                <label>
							<span>Indirizzo</span>
							<input   name="indirizzo" placeholder="Via esempio 23" required="required" type="text" />
						</label>

					</div>
                                    <div class="item">
                                                <label>
							<span>Username</span>
							<input   name="username" required="required"  type="text" />
						</label>
                                                <div class='tooltip help'>
							<span>?</span>
							<div class='content'>
								<b></b>
								<p>Username deve essere maggiore di 3 caratteri</p>
							</div>
						</div>
					</div>
					<div class="item">
						<label>
							<span>Password</span>
							<input type="password" name="password"  required='required'>
						</label>
						<div class='tooltip help'>
							<span>?</span>
							<div class='content'>
								<b></b>
								<p>Password deve essere maggiore di 6 caratteri</p>
							</div>
						</div>
					</div>
					<div class="item">
						<label>
							<span>Ripeti password</span>
							<input type="password" name="password2" data-validate-linked='password' required='required'>
						</label>
					</div>





				</fieldset>
                        </blockquote>

				<button name="registrazione" id='send' type='submit'>Registrati</button>
			</form>
		</section>
	</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="inc/js/multifield.js"></script>
    <script src="inc/js/validator.js"></script>
	<script>
		// initialize the validator function
		validator.message['date'] = 'not a real date';

		// validate a field on "blur" event, a 'select' on 'change' event & a '.reuired' classed multifield on 'keyup':
		$('form')
			.on('blur', 'input[required], input.optional, select.required', validator.checkField)
			.on('change', 'select.required', validator.checkField);

		$('.multi.required')
			.on('keyup', 'input', function(){
				validator.checkField.apply( $(this).siblings().last()[0] );
			}).on('blur', 'input', function(){
				validator.checkField.apply( $(this).siblings().last()[0] );
			});

		// bind the validation to the form submit event
		//$('#send').click('submit');//.prop('disabled', true);

		$('form').submit(function(e){
			e.preventDefault();
			var submit = true;
			// evaluate the form using generic validaing
			if( !validator.checkAll( $(this) ) ){
				submit = false;
			}

			if( submit )
				this.submit();
			return false;
		});

		/* FOR DEMO ONLY */
		$('#vfields').change(function(){
			$('form').toggleClass('mode2');
		}).prop('checked',false);

		$('#alerts').change(function(){
			validator.defaults.alerts = (this.checked) ? false : true;
			if( this.checked )
				$('form .alert').remove();
		}).prop('checked',false);
	</script>

    <!--<div id="One">
          <H2>&raquo; Registrati</H2>

                    <fieldset>
                    <legend>Registrazione</legend>
//                     <?php
//                    $registrazione = new form("index.php", "POST", "login");
//
//                    $registrazione->open_form();
//
//                    $registrazione->add_input("nome", "text", "Nome:", "nome");
//                    $registrazione->add_input("cognome", "text", "Cognome:", "cognome");
//                    $registrazione->add_input("mail", "text", "Mail:", "mail");
//                    $registrazione->add_input("username", "text", "Username:", "username");
//                    $registrazione->add_input("password", "password", "Password:", "password");
//                    $registrazione->add_input("telefono", "text", "N. Telefono:", "telefono");
//                    $registrazione->add_input("cap", "text", "Cap:", "cap");
//                    $registrazione->add_input("citta", "text", "Citta:", "citta");
//                    $registrazione->add_input("data_nascita", "date", "Data di nascita:", "data_nascita");
//                    $registrazione->add_input("indirizzo", "text", "Indirizzo:", "indirizzo");
//
//                    $registrazione->add_button("submit", "registrati","Registrati");
//
//                    $registrazione->close_form();
//                    ?>
                    </fieldset>
                    </blockquote>
    </div>
</div>-->
</div>

<?php
    include ('inc/code/footer.php');
?>